<template>
  <div class="home-recommend">
    <h2>达人歌单</h2>
    <div class="wrapper" ref="wrapper">
      <ul class="content" ref="content">
        <li v-for="(item,index) in listData" :key="index">
          <div class="cover">
            <van-image :src="item.cover" radius="1rem"/>
            <span>{{ item.listen_num | numFilter(1) }}万</span>
          </div>
          <span>{{ item.title }}</span>
        </li>
      </ul>
    </div>
  </div>
</template>


<script>
import {getOfficialList} from '@/api/homeApi'
import {betterScrollHorizontal} from "@/common/betterScroll";

export default {
  data() {
    return {
      listData: []
    }
  },
  created() {
    this.getSongListData()
  },
  methods: {
    //获取推荐歌单数据
    async getSongListData() {
      const {list} = await getOfficialList()
      this.listData = list
      betterScrollHorizontal(
          this,
          this.$refs.wrapper,
          this.$refs.content,
          this.listData.length,
          10) //调用横向滚动的方法
    },

  },
  filters: {
    //  处理播放量的显示格式
    /*
    *  param num ： 小数位固定的位数
    *  param value ：处理的数量值
    * */
    numFilter(value, num) {
      return parseFloat(value / 10000).toFixed(num)
    }
  }
}
</script>

<style scoped>
h2 {
  margin-left: 0.2rem;
}

.wrapper {
  width: 100%;
  overflow: hidden;
}

ul.content li {
  display: inline-block;
  width: 10rem;
  vertical-align: top;
}

ul.content li * {
  margin: 0.1rem;
}

ul.content li > span {
  display: inline-block;
  width: 100%;
  font-size: 0.8rem;
  color: #54493B;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cover > span {
  position: absolute;
  right: 0.2rem;
  bottom: 0.3rem;
  background-color: rgba(255, 255, 255, .4);
  color: white;
  font-size: 14px;
  border-radius: 1rem;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
  box-sizing: border-box;

  display: inline-block;
}

.cover {
  position: relative;
}
</style>
